/**
 * 路由控制部分
 * @param angular
 * @param require
 * @returns
 */
define(['angular', 'require', 'angular-route'], function (angular, require) {
	// 定义模块
	var app = angular.module('app', ['ngRoute']);
	// 定义控制器
	app.controller('dashboardController', function ($scope) {
		$scope.name = 'Miya';
	});
	// 定义路由配置
	app.config(['$routeProvider', '$controllerProvider', function ($routeProvider, $controllerProvider) {
		$routeProvider
		.when('/a', {
			templateUrl: 'templates/a.html',
			controller: 'a',
			resolve:{
                delay : ctrlRegister('a', ['static/js/script/controllers/a.js'])
            }
		})
		.when('/b', {
			templateUrl: 'templates/b.html',
			controller: 'b',
			resolve:{
                delay : ctrlRegister('b', ['static/js/script/controllers/b.js'])
            }
		});
		
		/**
		 * 控制器注入方法
		 */
		function ctrlRegister (ctrlName, ctrlModule) {
            return function ($q) {
                var defer = $q.defer();
                require(ctrlModule, function (controller) {
                    $controllerProvider.register(ctrlName, controller);
                    defer.resolve();
                });
                return defer.promise;
            }
        }
	}]);
	
	return app;
});